package com.sy.controller.user;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sy.dto.CoursePageQueryDTO;
import com.sy.pojo.Course;
import com.sy.pojo.CourseType;
import com.sy.pojo.CourseUser;
import com.sy.pojo.Coursedetail;
import com.sy.properties.JwtProperties;
import com.sy.result.PageResult;
import com.sy.result.Result;
import com.sy.service.CourseService;
import com.sy.service.CourseTypeService;
import com.sy.service.CourseUserService;
import com.sy.service.CoursedetailService;
import com.sy.utils.FastDFSClient;
import com.sy.vo.CourseDetailVO;
import com.sy.vo.CourseIndexVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 用户端-课程管理
 */
@Api(tags = "用户端-课程相关接口")
@RestController("userCourseController")
@RequestMapping("/user/course")
@Slf4j
public class CourseController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private JwtProperties jwtProperties;

    /**
     * 用户端-首页课程查询
     * @return
     */
    @ApiOperation("用户端-首页课程查询")
    @GetMapping("/findAll")
    public Result<List<CourseIndexVO>> findAll() {
        // 调用业务层实现查询
        List<CourseIndexVO> allSales = courseService.findAllSales();
        return Result.success(allSales);
    }

    /**
     * 用户端-全部课程查询
     * @return
     */
    @ApiOperation("用户端-全部课程查询")
    @GetMapping("/findAllCourse")
    public Result<PageResult> findAllCourse(CoursePageQueryDTO coursePageQueryDTO) {
        // 打印日志
        log.info("用户端-全部课程查询：{}", coursePageQueryDTO);
        // 调用业务层实现查询
        PageResult pageResult = courseService.findAllCourse(coursePageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 用户端-查看课程详情
     * @param cid
     * @return
     */
    @ApiOperation("用户端-查看课程详情")
    @GetMapping("/getCourseDetail")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "cid", value = "课程cid",
                    required = true, dataTypeClass = Integer.class)
    )
    public Result getCourseDetail(Integer cid) {
        // 打印日志
        log.info("用户端-查看课程详情：{}", cid);
        // 调用业务层实现查询
        CourseDetailVO courseDetailVO = courseService.getCourseDetail(cid);
        return Result.success(courseDetailVO);
    }
}
